package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.aspect.GuiguLoginAspect;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.LastUserListenPlayVo;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;
    @Autowired
    private GuiguLoginAspect guiguLoginAspect;

	@Operation(summary = "更新播放进度")
	@GuiGuLogin
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
		userListenProcessService.updateListenProcess(userListenProcessVo);
		return Result.build(null, ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "获取声音的播放进度")
	@GuiGuLogin
	@GetMapping("/getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId){
		BigDecimal trackBreakSecond = userListenProcessService.getTrackBreakSecond(trackId);
		return Result.build(trackBreakSecond,ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "获取最近一次播放声音")
	@GuiGuLogin
	@GetMapping("/getLatelyTrack")
	public Result<LastUserListenPlayVo> getLatelyTrack(){
		LastUserListenPlayVo lastUserListenPlayVo = userListenProcessService.getLatelyTrack();
		return Result.build(lastUserListenPlayVo,ResultCodeEnum.SUCCESS);
	}
}

